#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
import logging
import math


def str_strim(str1):
    # 利用切片去掉字符串首尾空格
    if not str1:
        return str1
    i = 0
    while i < len(str1) and str1[i] == ' ':
        i = i + 1

    j = len(str1) - 1
    while j >= 0 and str1[j] == ' ':
        j = j - 1

    if i > j:
        return str1[i:]
    return str1[i:j + 1]


def triangle(a, b, c):
    # 输入三条边长，计算三角形的周长和面积
    if a+b <= c and b+c <= a and a+c <= b:
        print(u"三条边长{},{},{}不能构成三角形".format(a, b, c))
    else:
        tri_c = a+b+c
        tri_s = round(math.sqrt(tri_c*(tri_c-a)*(tri_c-b)*(tri_c-c))/4.0, 2)
        return tri_c, tri_s


if __name__ == "__main__":
    if str_strim('hello  ') != 'hello':
        print('测试失败!')
    elif str_strim('  hello') != 'hello':
        print('测试失败!')
    elif str_strim('  hello  ') != 'hello':
        print('测试失败!')
    elif str_strim('  hello  world  ') != 'hello  world':
        print('测试失败!')
    elif str_strim('') != '':
        print('测试失败!')
    elif str_strim('    ') != '':
        print('测试失败!')
    else:
        print('测试成功!')
    # 计算三角形的周长和面积
    print(triangle(4, 4, 5))

